home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 36 - Archivers (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 36 - Archivers (19xx)(Topik Public Domain)(PD)[WB].adf / Zoo / zall / AllFiles.asm < prev    next >
Assembly Source File  |  1990-10-07  |  9KB  |  220 lines

  1. ;  AllFiles Program source
  2. ;   Author: Mike Cargal
  3. ;   January  1989
  4.  
  5. True   EQU 0
  6. False  EQU -1 
  7.  
  8. ArpBaseR EQUR  A6
  9. WrkR     EQUR  A5
  10. LocR     EQUR  A4
  11.  
  12.        OPTION NL
  13.        INCLUDE 'libraries/arpbase.p'
  14.        INCLUDE 'libraries/dosextens.i'
  15.        INCLUDE 'exec/memory.i'
  16.        INCLUDE 'ltypes.i'   ; used to define neg offset structures
  17. ;                              for LINK and UNLK instructions       
  18.        OPTION L
  19.  
  20.        XREF    _LVOOpenLibrary
  21.        XREF    _LVOCloseLibrary
  22.        XREF    _LVOFindTask
  23.  
  24. FileNameLen  EQU 256   ; DOS says 255 max ,but I'm reading only
  25. ;                          and I want to keep long word alignment  
  26.  
  27.   STRUCTURE WrkStorage,0
  28.         APTR    ArgPtr
  29.         LONG    Initial_SP
  30.         LABEL   WorkSt_SizeOf
  31.         
  32.   STRUCTURE Parameters,0
  33.         L_APTR    CurrLock
  34.         L_APTR    DirPtr
  35.         L_STRUCT  FileName,FileNameLen
  36.         L_STRUCT  MyFib,fib_SIZEOF
  37.         L_LABEL   Parameters_SizeOf
  38.  
  39. _ABSExecBase EQU 4
  40. LineFeed     EQU 10
  41.  
  42. EXECALL: MACRO $\1
  43.        MOVE.L  A6,-(SP)        ; Save current A6
  44.        MOVEA.L _ABSExecBase,A6 ; Load Exec Base
  45.        JSR     _LVO\1(A6)      ; Jump to Subroutine
  46.        MOVE.L  (SP)+,A6        ; Restore A6
  47.        ENDM
  48.  
  49. ARPCALL: MACRO $\1
  50.        JSR     _LVO\1(A6)      ; Jump to Subroutine
  51.        ENDM
  52.  
  53. *      SECTION  CODE
  54. ******************************************************************
  55. *      Start of Code                                             *
  56. ******************************************************************
  57.        MOVEM.L D0/A0,-(SP)     ; Save command line ptr/len
  58.        MOVEQ.L #ArpVersion,D0  ; Current version of ARP
  59.        LEA     ArpNm,A1        ; Point to library name
  60.        EXECALL OpenLibrary     ; Open it up
  61.        MOVEA.L D0,ArpBaseR     ; Save ArpBaseR
  62.        TST.L   D0              ; Did we get NULL Pointer ?
  63.        BNE     ArpOpenOK       ; -NO- good
  64.        MOVEQ.L #ERROR_INVALID_RESIDENT_LIBRARY,D0
  65.        ADDQ    #8,SP           ; Reset Stack
  66.        RTS                     ; ARP didn't open (bad news)
  67. ArpOpenOK
  68.        MOVE.L  #WorkSt_SizeOf,D0 ; Size of working storage
  69.        ARPCALL ArpAlloc        ; Get working storage
  70.        MOVE.L  D0,WrkR         ; Use Wrk Reg to point to working stg
  71.        TST.L   D0              ; Did we get a NULL pointer ?
  72.        BNE     1$              ; -NO- good
  73.        ADDQ    #8,SP           ; -YES- Restore Stack Pointer
  74.        MOVE.L  #ERROR_NO_FREE_STORE,D0
  75.        BRA     AllocOut        ;   and exit program
  76. 1$
  77. ******************************************************************
  78. *   Process Command Line                                         *
  79. ******************************************************************
  80.        MOVEM.L (SP)+,D0/A0
  81.        MOVE.L  SP,Initial_SP(A5) ; Save Stack Pointer
  82. *       MOVE.L  #CLSTRING,A0    ;  ***** TEST CODE *****
  83. *       MOVE.L  #CLSTRINGLEN,D0 ;  ***** TEST CODE *****
  84.        LEA     HelpString,A1   ; Point to help text
  85.        LEA     ArgPtr(A5),A2   ; Point to Arg array
  86.        LEA     Template,A3     ; Point to Command Template
  87.        ARPCALL GADS            ; Edit Command Line input
  88.        CMPI.L  #-1,D0          ; Error return ?
  89.        BNE     CL_OK           ; - No -
  90.        MOVE.L  #ERROR_ACTION_NOT_KNOWN,D0  ; - Yes - Set error code
  91.        BRA     ERROR           ; and exit
  92. CL_OK
  93.        TST.L   D0              ; Any Arguments ?
  94.        BEQ     NoDirSpec       ; - No - use current dir
  95. NextArg
  96.        MOVEA.L ArgPtr(WrkR),A1 ; get arg pointer
  97.        TST.L   (A1)            ; NULL pointer ?
  98.        BEQ.S   Done            ; -yes- then we're done
  99.        MOVEA.L (A1)+,A0        ; A0 points to current arg
  100.        MOVE.L  A1,ArgPtr(WrkR) ; Pointer to next arg ptr
  101.        BSR     ListDir         ; Call Recursive routine to Process Arg
  102.        BRA.S   NextArg         ; Get Next Arg
  103. NoDirSpec
  104.        LEA     zbyte,A0
  105.        BSR     ListDir         ; Call recursive routine to process
  106. Done                           ;   current dir
  107.        MOVE.L  Initial_SP(A5),SP ; Restore initial Stack pointer
  108.        MOVEA.L ArpBaseR,A1     ; Point to ARP library
  109.        EXECALL CloseLibrary    ;   and close it
  110.        MOVEQ   #0,D0           ; Set good return code
  111.        RTS                     ; See ya later
  112. ******************************************************************
  113. *      Recursive subroutine to print directories listings        *
  114. *         at entry A0 points to directory name                   *
  115. ******************************************************************
  116. ListDir 
  117.        LINK    LocR,#Parameters_SizeOf ; allocate work strg on stack
  118.        MOVE.L  A0,DirPtr(LocR) ; save pointer to directory name
  119.        MOVE.L  A0,D1           ; move to D1 to get lock
  120.        MOVE.L  #ACCESS_READ,D2 ; request read lock
  121.        ARPCALL ArpLock         ; get lock
  122.        MOVE.L  D0,CurrLock(LocR) ; save lock
  123.        BNE     1$              ; process if not NULL
  124.        MOVE.L  #ERROR_OBJECT_NOT_FOUND,D0 ; error if null
  125.        BRA     ErrOut
  126. 1$
  127.        LEA     MyFib(LocR),A0  ; point to my File Info Blk
  128.        MOVE.L  A0,D2           ; put pointer in D2 for Examine
  129.        MOVE.L  CurrLock(LocR),D1 ; move current lock to D1
  130.        ARPCALL Examine         ; Examine current lock
  131.        TST.L   D0              ; check return
  132.        BEQ.S   LD_Exit         ;  if zero then get outa here
  133. LD_Loop
  134.        LEA     _LVOPuts(ArpBaseR),A1 ; put break message if broke
  135.        ARPCALL CheckAbort      ; Check for ctrl-c etc.
  136.        TST.L   D0              ; aborted ?
  137.        BNE     Done            ; -yes-
  138.        LEA     MyFib(LocR),A0  ; point to my File Info Blk
  139.        MOVE.L  A0,D2           ; put pointer in D2 for Examine
  140.        MOVE.L  CurrLock(LocR),D1 ; move current lock to D1
  141.        ARPCALL ExNext          ; examine next entry 
  142.        TST.L   D0              ; check return
  143.        BNE.S   LD_First        ; non-zero is good
  144.        ARPCALL IoErr           ; what was the problem ?
  145.        CMPI.L  #ERROR_NO_MORE_ENTRIES,D0 ; no more entries ?
  146.        BEQ.S   LD_Exit         ; -yes- finished with this level
  147.        BRA.S   ERROR           ; -no- we've got a problem                       
  148. LD_First
  149.        MOVEA.L DirPtr(LocR),A0 ; point A0 to directory name
  150.        LEA     MyFib+fib_FileName(LocR),A1 ; point A1 to entry name
  151.        LEA     FileName(LocR),A2 ; point to local name buffer
  152.        BSR     ConcatName      ; concatenate them
  153.        TST.L   MyFib+fib_DirEntryType(LocR) ; is this entry a dir ?
  154.        BMI.S   PutFile         ; -no- print file name 
  155.        LEA     FileName(LocR),A0 ; -yes- point A0 to directory name 
  156.        BSR     ListDir         ; and call this rtn recursively
  157.        BRA.S   LD_Loop         ; when we get back, continue on where 
  158. PutFile                        ;   we left off
  159.        LEA     FileName(LocR),A1 ; point to file name
  160.        ARPCALL Puts            ; print it to stdout
  161.        BRA.S   LD_Loop         ; and carry on
  162. LD_Exit
  163.        UNLK    LocR            ; deallocate storage on stack
  164.        RTS                     ; and exit this level
  165. ******************************************************************
  166. **    Concatenate two strings with a '/' between them           **
  167. **       A0 - Points to Directory Name                          **
  168. **       A1 - Points to name to append after '/'                **
  169. **       A2 - Points to destination buffer                      **
  170. ******************************************************************
  171. ConcatName
  172.        MOVE.L  #FileNameLen,D0 ; max length of file name
  173.        CMPI.B  #0,(A0)
  174.        BEQ.S   MoveEntry
  175. 1$     MOVE.B  (A0)+,(A2)+     ; move directory to buffer
  176.        DBEQ    D0,1$
  177.        TST.L   D0              ; did we fill buffer (shouldn't happen)
  178.        BEQ     ErrOut          ; -yes- then we've got a problem
  179.        CMPI.B  #':',-2(A2)     ; was it a device
  180.        BNE     NotDev          ; -no-
  181.        LEA     -1(A2),A2       ; -yes- back up over 0 byte
  182.        ADDQ.L  #1,D0           ; add one back to byte count
  183.        BRA.S   MoveEntry       ; and don't put '/'
  184. NotDev         
  185.        MOVE.B  #'/',-1(A2)     ; put '/' after directory name
  186. MoveEntry       
  187. 2$     MOVE.B  (A1)+,(A2)+     ; add new entry name (file or dir) 
  188.        DBEQ    D0,2$    
  189.        RTS                     ; and return
  190. ******************************************************************
  191.                      
  192. ERROR 
  193.        ARPCALL IoErr           ; find error code
  194.        MOVE.L  D0,D2           ; put it in reg D2 for WHY Command
  195.        MOVE.L  #RETURN_ERROR,D0 ; set error return code
  196. ErrOut
  197.        MOVE.L  Initial_SP(A5),SP ; Restore initial stack pointer
  198. AllocOut
  199.        MOVEA.L ArpBaseR,A1     ; Point to ARP library
  200.        EXECALL CloseLibrary    ;   and close it
  201.        RTS                     ; See ya later
  202. ******************************************************************
  203.  
  204. ;       SECTION DATA,DATA
  205. ArpNm      CSTRING 'arp.library'
  206.  
  207. ;CLString     DC.B 'includes'
  208. ;CLStringLen  EQU *-CLString
  209. ;             DC.B 0
  210.  
  211. Template   CSTRING 'Directory/...' 
  212.  
  213. HelpString DC.B 'FAll with no arguments will list all files in the',LineFeed
  214.   DC.B 'current directory, and any subdirectories. If you specify',LineFeed
  215.   DC.B 'a directory(s), the same will be done for the directories',LineFeed
  216.   DC.B 'specified.  In both cases, files will be listed with the',LineFeed
  217.   DC.B 'full file name needed to access them from your current directory'
  218.   DC.B LineFeed,0
  219. zbyte DC.B 0
  220.            END